package org.devocean.groupbuying.web.backend;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.devocean.groupbuying.domain.Compatibility;
import org.devocean.groupbuying.service.CompatibilityService;
import org.devocean.groupbuying.utils.RenderMapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


@Controller
@RequestMapping(value = { "/gb-cpanel/compatibilities"})
public class CompatibilitiesController {
	
	@Autowired
	CompatibilityService compatibilityService;
	
	@RequestMapping(value="/")
	public Map<String, ? extends Object> list(@RequestParam String start,@RequestParam String limit){
		List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
		List<Compatibility> compatibilities = compatibilityService.getAllCompatibilities();
		for (Compatibility comp : compatibilities) {
		
			Map<String, Object> compabilitysmap = new  ConcurrentHashMap<String, Object>();
			compabilitysmap.put("compatibilityID", comp.getCompatibilityID());
			compabilitysmap.put("compatibilitykey", comp.getCompatibilitykey());
			compabilitysmap.put("value", comp.getValue());
			result.add(compabilitysmap);
		}
		Long total = compatibilityService.countCompatibility();
		try{
			return RenderMapUtils.getMap(result, total) ;
			
		
		}catch (Exception e) {
		return RenderMapUtils
				.getModelMapError("Error retrieving Articles from database.");
	}
	}

}
